# -*- encoding: utf8 -*-
from django.db import models
import datetime

class Group (models.Model):
    MEDIA_RETENTION = (
        (u'1 Week', u'1 Week'),
        (u'1 Month', u'1 Month'),
        (u'1 Year', u'1 Year'),
        (u'5 Year', u'5 Year'),
        (u'Other', u'Other')
        )
    name = models.CharField('Nome', max_length=10)
    retentionWeek = models.CharField('Retenção Semanal', choices=MEDIA_RETENTION, max_length=15, blank=True)
    otherWeek = models.CharField('Outro', max_length=25, blank=True)
    retentionMonth = models.CharField('Retenção Mensal', choices=MEDIA_RETENTION, max_length=15, blank=True)
    otherMonth = models.CharField('Outro', max_length=25, blank=True)
    retentionYear = models.CharField('Retenção Anual', choices=MEDIA_RETENTION, max_length=15, blank=True)
    otherYear = models.CharField('Outro', max_length=25, blank=True)
    serviceResponsible = models.CharField('Responsável pelo Serviço', max_length=15)
    
    def __unicode__(self):
        return(self.name)
    
class Media (models.Model):
    MEDIA_CHOICES = (
        (u'3480', u'Cartucho 3480'),
        (u'3590', u'Cartucho 3590'),
        (u'LTO 3', u'Cartucho LTO 3'),
        (u'LTO 4', u'Cartucho LTO 4'),
        (u'LTO 5', u'Cartucho LTO 5'),
        (u'LTO 6', u'Cartucho LTO 6')
        )
    MEDIA_STATUS = (
        (u'Disponivel', u'Disponivel'),
        (u'Liberada', u'Liberada'),
        (u'Retida', u'Retida'),
        (u'Backup Externo', u'Backup Externo'),
        (u'Defeito', u'Defeito'),
        (u'Descartada', u'Descartada'),
        (u'Retirada', u'Retirada')
        )
    MEDIA_ROUTINE = (
        (u'S1', u'Semanal 1'),
        (u'S2', u'Semanal 2'),
        (u'S3', u'Semanal 3'),
        (u'S4', u'Semanal 4'),
        (u'S5', u'Semanal 5'),
        (u'Mensal', u'Mensal'),
        (u'Anual', u'Anual')
        )
    SOFTWARE = (
        (u'Networker', u'Networker'),
        (u'Netvault', u'Netvault'),
        )        
    numberMedia = models.IntegerField('Número Mídia', primary_key=True)
    typeMedia = models.CharField('Tipo Mídia', default='LTO 4', choices=MEDIA_CHOICES, max_length=15)
    implantationTime = models.DateTimeField('Data da Implantação', default=datetime.datetime.now())
    statusMedia = models.CharField('Status', default=u'Disponivel', choices=MEDIA_STATUS, max_length=15)
    group = models.ForeignKey(Group)
    label = models.CharField('Label', max_length=25)
    advertiseLabel = models.CharField('Observação', max_length=100, blank=True)
    software = models.CharField('Software de Backup', choices=SOFTWARE, default=u'Networker', max_length=15)
    routine = models.CharField('Rotina', choices=MEDIA_ROUTINE, max_length=15, blank=True)
    referenceTime = models.DateField('Período de Referencia', blank=True, null=True, default=datetime.datetime.now()) 
    
    def get_media_lifetime_month (self):
        today = datetime.date.today()
        return (int)((today - self.implantationTime) / 30)
    
    def __str__(self):
        return u"%s %s" % (self.numberMedia, self.group.name)                 

class Discart(models.Model):
    media = models.ForeignKey(Media)
    discardOccurrence = models.IntegerField('Número da Ocorrência de Descarte')
    requestingDiscart = models.CharField('Solicitante de Descarte', max_length=15)
    discartTime = models.DateTimeField('Data de Descarte')
    
class Liberation(models.Model):
    media = models.ForeignKey(Media)
    liberationOccurrence = models.IntegerField('Número da Ocorrência de Liberação')
    requestingLiberation = models.CharField('Solicitante da Liberação', max_length=15)
    liberationTime = models.DateTimeField('Data de Liberação')
    
class Removal(models.Model):
    media = models.ForeignKey(Media)
    removalOccurrence = models.IntegerField('Número da Ocorrência de Retirada')
    requestingRemoval = models.CharField('Solicitante de Retirada', max_length=15)
    removalTime = models.DateTimeField('Data de Retirada')



